angular.module('starter')
.controller('onedayCtrl', function($scope,meilvFac,$stateParams, $ionicScrollDelegate) {
    $scope.userCollection=function(id){
        meilvFac.collection.collectionadd(
            {article_id:id},
            function(data){
                $scope.hasMore=true;
                $scope.page=0;
                $scope.oneday=[];
                $scope.getRecommends();
            },
            function(data){
                console.log(data.info)
            }
        )
    }
        $scope.hasMore=true;
        $scope.page=0;
        $scope.oneday=[];
        $scope.getRecommends = function() {
            $scope.page++;
            if($stateParams.filter){
                var sendFilter=$stateParams.filter;
            }
            else{
                var sendFilter=null;
            }
            meilvFac.articleshow.index(
                {
                    article_id:-1,
                    page:$scope.page,
                    limit:2,
                    filter:sendFilter
                },
                function(data) {
                // if(!data.success){
                //     $scope.hasMore=false;
                //     return;
                // }
                if (data.info && data.info.length) {
                    angular.forEach(data.info, function(s) {
                        $scope.oneday.push(s);
                        $ionicScrollDelegate.resize();
                    })
                } else {
                    $scope.hasMore = false;
                }
                $scope.$broadcast('scroll.infiniteScrollComplete');
            }, function(data) {
                alert(data);
            });
        }
        $scope.searchMeilv=function(){
            meilvFac.articleshow.index(
                {search:$scope.search},
                function(data){
                    $scope.search = null;
                    $scope.oneday=data.info;
                    if(data.success==false){
                        alert("找不到文章")
                        $scope.hasMore=false;
                    }
                },
                function(data){
                    alert(data)
                }
            )
        }
})